// import { def, isString, keys } from "./utils";
// import { Observer } from "./observer";

class Vue {
  constructor(options) {
    this.$options = options || {};

    this.$el = isString(options.el) ?
      document.querySelector(options.el) :
      options.el;

    this.$data = options.data ?? {};

    for (const method in options.methods) {
      this[method] = options.methods[method].bind(this);
    };

    this._proxyData(this.$data);

    new Observer(this.$data);

    new Compiler(this);
  }

  _proxyData(data) {
    keys(data).forEach(key => {
      def(this, key, {
        configurable: true,
        enumerable: true,
        get() {
          return data[key]
        },
        set(v) {
          if (data[key] !== v) {
            data[key] = v;
          }
        }
      })
    })
  }
}